package com.hq.commons.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {

    private static final String SUCCESS = "success";

    private static final String ERROR = "error";

    private String status;

    private String msg;

    private T data;

    public static R success() {
        return new R(SUCCESS, null, null);
    }

    public static R success(Object data) {
        return new R(SUCCESS, null, data);
    }

    public static R error(String msg) {
        return new R(ERROR, msg, null);
    }

    public static R write(Object tar) {
        if (tar instanceof Boolean) {
            Boolean flag = (Boolean) tar;
            if (flag) {
                return R.success();
            } else {
                return R.error("添加失败");
            }
        }
        return error(null);
    }
}
